package ca.etsmtl.log660.view;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import ca.etsmtl.log660.entity.Film;
import ca.etsmtl.log660.entity.Personne;
import ca.etsmtl.log660.servlet.Controler;

public class FrameSystem {

	private JFrame frame  = new JFrame("Log660 lab2");
	private RechercheFilm recherchePanel;
	private Login loginPanel;
	private DetailFilm filmPanel;
	private DetailPersonne personnePanel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		Controler.getControler();
	}

	/**
	 * Create the application.
	 */
	public FrameSystem() {
		initialize();
		frame.addWindowListener (new WindowAdapter(){
			public void windowClosing (WindowEvent e){
				System.exit(0);
			}
		});
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		loginPanel = new Login();
		frame.add(loginPanel);
		frame.pack();
		frame.setVisible(true);
	}
	
	public void ouvrirRecherche(){
		recherchePanel = new RechercheFilm();
		frame.remove(loginPanel);
		frame.add(recherchePanel);
		frame.pack();
	}
	
	public void ouvrirFilm(Film film){
		filmPanel = new DetailFilm();
		filmPanel.remplirChamps(film);
		frame.remove(recherchePanel);
		frame.add(filmPanel);
		frame.pack();
	}
	
	public void ouvrirPersonne(Personne personne){
		personnePanel = new DetailPersonne();
		personnePanel.RemplirChamps(personne);
		frame.remove(filmPanel);
		frame.add(personnePanel);
		frame.pack();
	}
	
	public void retourFilm(){
		frame.remove(personnePanel);
		frame.add(filmPanel);
		frame.pack();
	}
	
	public void retourRecherche(){
		frame.remove(filmPanel);
		frame.add(recherchePanel);
		frame.pack();
	}
}
